package com.ning.cloud.user.controller.api;

import com.ning.cloud.common.util.Response;
import com.ning.cloud.user.api.dto.UserDTO;
import com.ning.cloud.user.dto.UserRegisterDTO;
import com.ning.cloud.user.request.UserRegisterRequest;
import com.ning.cloud.user.service.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("/openapi/user")
@Slf4j
@Tag(name = "openapi:用户管理模块")
public class UserApi {

    @Resource
    AdminUserService adminUserService;

    @GetMapping("/{id}")
    @Operation(summary = "查询用户信息")
    public Response<UserDTO> getUserById(@PathVariable("id") Long id) {
        UserDTO userDTO = UserDTO.builder().id(id).name("test").build();
        return Response.success(userDTO);
    }

    @PostMapping("/register")
    @Operation(summary = "用户注册")
    @Parameter(name="Authorization", in= ParameterIn.HEADER, required = true)
    public Response<UserRegisterDTO> register(@RequestBody @Valid UserRegisterRequest userRegisterRequest){
        UserRegisterDTO userRegisterDTO = adminUserService.register(userRegisterRequest);
        return Response.success(userRegisterDTO);
    }


}
